package util;

import java.util.HashMap;

public class Demo {
    public static void main(String[] args) {
        String url = "https://ocrapi-advanced.taobao.com/ocrservice/advanced";
        String appcode = "你自己的AppCode";
        HashMap<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/json; charset=UTF-8");
        //如果需要使用本地图片，需要将图片base64码放在img后面，如果使用网络图片，则需要将网络图片url放于url参数后面
        String bodys = "{\"img\":\"\",\"url\":\"\",\"prob\":false,\"charInfo\":false,\"rotate\":false,\"table\":false}";
        try {
            /**
             2    	* 重要提示如下:
             2    	* HttpClientUtils请从
             2    	* https://gitee.com/duguangdemo/publicclouddemo/blob/master/src/main/java/util/HttpClientUtils.java
             2    	* 下载
             2    	* HttpExecuteResponse请从
             2    	* https://gitee.com/duguangdemo/publicclouddemo/blob/master/src/main/java/util/HttpExecuteResponse.java
             2    	* 下载
             2    	*
             2    	* 相应的依赖请参照
             2    	* https://gitee.com/duguangdemo/publicclouddemo/blob/master/pom.xml
             2    	*/
            HttpExecuteResponse response = HttpClientUtils.doPost(url,bodys, headers);
            System.out.println(response.getResponseAsString());
            System.out.println(response.toString());
            //需要检查response的headers信息时可用以下代码,方便排查问题用
            //for (Object json : response.getHeaders()) {
            //    System.out.println(json);
            //}

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
